#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,copy
import codecs
files=['']
path = "./old/" #文件夹目录
files= os.listdir(path) #得到文件夹下的所有文件名称
s = []
for file in files: #遍历文件夹
    print(file) #打印结果
    fobj = codecs.open(path+file, encoding='UTF-16')
    new_lines = []
    out = open("./u-phi/"+file,'w')
    lines = fobj.readlines()
    new_lines.append(';para start\r\n')
    new_lines.append( 'ELECTRODENO=1920;\r\n')
    new_lines.append('ELECTRODEWIDTH=3e-6\r\n')
    new_lines.append('ELECTRODEGAP=2e-6;\r\n')
    new_lines.append('ELECTRODELENGTH=15e-3;\r\n')
    new_lines.append('THICKNESS=11e-6;\r\n')
    new_lines.append('LIQUIDCRYSTAL=YM8;\r\n')
    new_lines.append(';para end\r\n')
    new_lines.append(';u-phi start\r\n')
    new_lines.append('U\tP@1064nm\n')

    cpy_lines = copy.deepcopy(lines)
    print "lines",len(lines)
    # out.write(new_lines[0])
    # out.write(new_lines[1])
    # out.write(new_lines[2])
    # out.write(new_lines[3])
    # out.write(new_lines[4])
    # out.write(new_lines[5])
    # out.write(new_lines[6])
    # out.write(new_lines[7])
    # out.write(new_lines[8])
    for i in range(6,207):
        v = ((cpy_lines[212-i].split('\t'))[1]).decode('utf-8')
        #print isinstance(v, 'utf-8')
        print v
        #print float(v)
        new_lines.append(("%d\t%s"%(i-6,v.decode('utf-8'))))
        # new_lines[i] = (new_lines[i].encode('utf-8'))
        # out.write(new_lines[i])
    new_lines.append(";u-phi end\r\n")
    out.writelines(new_lines)
    # out.write(";u-phi end")
    # for line in lines:
    #     print 'wriet line',line
    out.flush()
    out.close()